<template>
  <el-select
    ref="select"
    v-model="content"
    filterable
    remote
    clearable
    default-first-option
    placeholder="请输入名称搜索"
    :remote-method="remoteMethod"
    :loading="loading"
    v-bind="$attrs"
    @blur.native.capture="nameblur()"
    @change="change"
  >
    <el-option
      v-for="item in list"
      :key="item.id"
      :label="item.sName"
      :value="item.sName"
    >
      <!-- 自定义选择显示值 -->
      <template>
        <div class="itemBox">
          <span>{{ item.sName }} </span>
          <!-- <span>{{ item.oldFacilitiyNo }}</span> -->
        </div>
      </template>
    </el-option>
  </el-select>
</template>

<script>
/*
选择店铺-单选

import selectStoreList from '@/components/xm/selectStoreList/selectStoreList'

<selectStoreList v-model.trim="model.oldFacilitiyNo" />

*/
import { postAction } from '@/api/manage'

export default {
  components: {},
  model: {
    prop: 'sName',
    event: 'change'
  },
  props: {
    // 搜索名称
    sName: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      loading: false,
      list: []
    }
  },
  computed: {
    content: {
      get() {
        return this.sName
      },
      set(val) {
        this.$emit('change', val)
      }
    }
  },
  mounted() {
    console.log('mounted')
    this.getList('')
  },
  methods: {
    // 获取列表
    getList(sName) {
      this.loading = true
      postAction('storeList.aspx?action=GetList', { sName, pageSize: 200, pageNum: 1 }).then(res => {
        if (res.code === 1) {
          this.list = res.data.list
        }
      }).finally(() => {
        this.loading = false
      })
    },
    nameblur() {
      // this.$emit('change', this.$refs.select.selectedLabel)
      // this.content = this.$refs.select.selectedLabel
      // this.getList()
    },
    // 远程搜索
    remoteMethod(sName) {
      this.getList(sName)
    },
    change(val) {
      // const obj = this.list.find(v => v.oldFacilitiyNo === val) || {}
      // this.$emit('change', obj)
    }
  }
}

</script>
<style scoped lang='scss'>
.el-select{
  width:100%;
}
.itemBox{
  display:flex;
  justify-content:space-between;
}
</style>
